import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import path from 'path'

// https://vitejs.dev/config/
export default defineConfig({
  root: './src/',
  base: '/',
  envDir: '../',
  build: {
    // ...
    // 指定输出目录
    outDir: path.resolve(__dirname, 'dist'),
    assetsDir: '',
    // 启用、禁用css代码拆分
    cssCodeSplit: true,
    // 构建是否生成source map文件
    sourcemap: 'inline',
    // rollup 配置打包项
    rollupOptions: {
      // ...
      // input:"src/index.js"
      input: {
        main: path.resolve(__dirname, 'src/pages/main/index.html'),
        userCenter: path.resolve(__dirname, 'src/pages/userCenter/index.html'),
      },
      output: {
        chunkFileNames: 'static/js/[name]-[hash].js',
        entryFileNames: 'static/js/[name]-[hash].js',
        assetFileNames: 'static/[ext]/[name]-[hash].[ext]',
      },
    },
  },
  plugins: [react()],
  resolve: {
    // 配置别名 @为src引入
    alias: {
      '@': path.resolve(__dirname, 'src'),
    },
  },
  css: {
    preprocessorOptions: {
      less: {
        modifyVars: {
          // 更改主题在这里
          // 'primary-color': '#52c41a',
          // 'link-color': '#1DA57A',
          // 'border-radius-base': '2px',
        },
        javascriptEnabled: true,
      },
    },
  },
  server: {
    host: '0.0.0.0',
    proxy: {
      '/api': {
        target: 'http://192.168.3.155:3000',
        ws: false,
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api/, ''),
      },
    },
  },
})
